package com.app.xinfadi.ui.center_role_purchase_plan;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.xinfadi.R;
import com.app.xinfadi.base.BaseFragment;
import com.app.xinfadi.ui.MainActivity;
import com.app.xinfadi.ui.center_role_purchase_plan.view.CenterRolePurchasePlanPagerAdapter;
import com.app.xinfadi.widget.NoScrollViewpager;
import com.app.xinfadi.widget.sliding_tab.SlidingTabLayout;

import java.util.ArrayList;

/**
 * function: 中心角色 采购计划
 * Created by Wutengfei on 2016/1/27.
 */
public class CenterRolePurchasePlanFragment extends BaseFragment {
    private View view;
    private NoScrollViewpager mViewPager;
    private FragmentPagerAdapter mAdapter;
    private ArrayList<Fragment> purchasePlanFragmentList;
    private ViewPager.OnPageChangeListener mViewPagerOnPageChangeListener;

    public static CenterRolePurchasePlanFragment getInstance() {
        CenterRolePurchasePlanFragment instance = new CenterRolePurchasePlanFragment();
        Bundle args = new Bundle();
//      args.putString("status", status);
        instance.setArguments(args);
        return instance;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.purchase_plan_layout_fragment, null);
        initView();
        initData();
        return view;
    }

    private void initView() {

        mViewPager = (NoScrollViewpager) view.findViewById(R.id.id_viewpager);
        mViewPager.setOffscreenPageLimit(3);
        purchasePlanFragmentList = new ArrayList<>();
        purchasePlanFragmentList.add(ExamineAndApproveListFragment.getInstance());
        purchasePlanFragmentList.add(CenterRoleAddPurchasePlanFragment.getInstance());

        mViewPagerOnPageChangeListener = new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        };
        mViewPager.addOnPageChangeListener(mViewPagerOnPageChangeListener);

        mAdapter = new CenterRolePurchasePlanPagerAdapter(getChildFragmentManager(), purchasePlanFragmentList);
        mViewPager.setAdapter(mAdapter);

//        SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
        SlidingTabLayout mSlidingTabLayout = ((MainActivity)context).sliding_tabs_center_role;
//        mSlidingTabLayout.setDistributeEvenly(true);//平铺
        mSlidingTabLayout.setCustomTabView(R.layout.comm_lay_tab_indicator, android.R.id.text1);
        mSlidingTabLayout.setSelectedIndicatorColors(Color.parseColor("#ffffffff"));
        mSlidingTabLayout.setViewPager(mViewPager);
    }

    private void initData() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
        }
    }

    private void selectTopButton() {

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        mViewPager.removeOnPageChangeListener(mViewPagerOnPageChangeListener);
    }
    public class ViewPagerAdapter extends FragmentPagerAdapter {

        private final int totalPaginas = 3;
        private String[] titulos;

        public ViewPagerAdapter(FragmentManager fm, String[] titulos) {
            super(fm);
            this.titulos = titulos;
        }

        @Override
        public Fragment getItem(int position) {
//            Fragment tab = TabFragment.getInstance(titles[position]);

            return null;
        }

        public CharSequence getPageTitle(int position) {
            return titulos[position];
        }

        @Override
        public int getCount() {
            return totalPaginas;
        }
    }
}
